<template>
  <el-form
    :model="form"
    :rules="rules"
    ref="formRef"
    label-width="80px"
    class="login-form"
  >
    <el-form-item label="用户名" prop="username">
      <el-input v-model="form.username" placeholder="请输入用户名" />
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input
        v-model="form.password"
        type="password"
        placeholder="请输入密码"
      />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSubmit">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import { ElMessage, ElForm } from 'element-plus'

const formRef = ref<InstanceType<typeof ElForm> | null>(null)
const form = reactive({
  username: '',
  password: '',
})

const rules = reactive({
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
})

const handleSubmit = () => {
  // 表单验证
  formRef.value?.validate((valid: boolean) => {
    if (valid) {
      ElMessage.success('登录成功！')
    }
  })
}
</script>

<style scoped>
/* 样式部分可以根据需要添加 */
</style>  